<?php
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

/**
 * Class PermissionSeeder
 */
class PermissionSeeder extends Seeder{

    public function run(){
        $tableNames = config('permission.table_names');
        $date = date('Y-m-d H:i:s');
        $permissions = [
            [
                'name'=>'roles.index',
                'description' => '角色列表',
                'group'=>'权限组',
                'menu' => '系统管理',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'roles.store',
                'description' => '新增角色',
                'group'=>'权限组',
                'menu' => '系统管理',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'roles.update',
                'description'=>'编辑角色',
                'group'=>'权限组',
                'menu' => '系统管理',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'roles.destroy',
                'description'=>'删除角色',
                'group'=>'权限组',
                'menu' => '系统管理',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'admins.index',
                'description' => '管理员列表',
                'group'=>'管理员',
                'menu' => '系统管理',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'admins.store',
                'description' => '新增管理员',
                'group'=>'管理员',
                'menu' => '系统管理',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'admins.update',
                'description'=>'编辑管理员',
                'group'=>'管理员',
                'menu' => '系统管理',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'wechat-menus.store',
                'description'=>'添加子菜单',
                'group'=>'自定义菜单',
                'menu' => '微信设置',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'wechat-menus.update',
                'description'=>'编辑菜单',
                'group'=>'自定义菜单',
                'menu' => '微信设置',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'wechat-menus.destroy',
                'description'=>'删除菜单',
                'group'=>'自定义菜单',
                'menu' => '微信设置',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'wechat-menu-applications.store',
                'description'=>'应用微信菜单',
                'group'=>'自定义菜单',
                'menu' => '微信设置',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'wechat-groups.index',
                'description'=>'菜单组列表',
                'group'=>'自定义菜单',
                'menu' => '微信设置',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'wechat-groups.store',
                'description'=>'新增菜单组',
                'group'=>'自定义菜单',
                'menu' => '微信设置',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'wechat-groups.update',
                'description'=>'编辑菜单组',
                'group'=>'自定义菜单',
                'menu' => '微信设置',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'wechat-groups.show',
                'description'=>'菜单组详情',
                'group'=>'自定义菜单',
                'menu' => '微信设置',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'wechat-messages.index',
                'description'=>'微信自动回复',
                'group'=>'微信自动回复',
                'menu' => '微信设置',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'wechat-messages.store',
                'description'=>'添加自动回复规则',
                'group'=>'微信自动回复',
                'menu' => '微信设置',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'wechat-messages.update',
                'description'=>'编辑回复规则',
                'group'=>'微信自动回复',
                'menu' => '微信设置',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'wechat-messages.destroy',
                'description'=>'删除回复规则',
                'group'=>'微信自动回复',
                'menu' => '微信设置',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'wechat-medias.index',
                'description'=>'素材列表',
                'group'=>'素材列表',
                'menu'=>'微信设置',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'schools.index',
                'description'=>'学校列表',
                'group'=>'学校列表',
                'menu' => '学校设置',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'schools.store',
                'description'=>'添加学校信息',
                'group'=>'学校列表',
                'menu' => '学校设置',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'schools.update',
                'description'=>'编辑学校信息',
                'group'=>'学校列表',
                'menu' => '学校设置',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'school-rules.update',
                'description'=>'修改学校规则',
                'group'=>'学校规则列表',
                'menu' => '学校设置',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=> 'school-admins.index',
                'description'=>'列表',
                'group'=>'学校管理员',
                'menu' => '学校设置',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=> 'school-admins.store',
                'description'=>'新增',
                'group'=>'学校管理员',
                'menu' => '学校设置',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=> 'school-admins.update',
                'description'=>'编辑',
                'group'=>'学校管理员',
                'menu' => '学校设置',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=> 'school-admins.refresh',
                'description'=>'重置管理员密码',
                'group'=>'学校管理员',
                'menu' => '学校设置',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=> 'school-admins.show',
                'description'=>'展示学校已有管理员和权限',
                'group'=>'学校管理员',
                'menu' => '学校设置',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'users.index',
                'description'=>'用户列表',
                'group'=>'用户列表',
                'menu' => '用户管理',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name' => 'users.store',
                'description' => '新增用户',
                'group' => '用户列表',
                'menu' => '用户管理',
                'guard_name'=>'backend',
                'created_at' => $date,
                'updated_at' => $date
            ],
            [
                'name' => 'users.update',
                'description' => '编辑用户',
                'group' => '用户列表',
                'menu' => '用户管理',
                'guard_name'=>'backend',
                'created_at' => $date,
                'updated_at' => $date
            ],
            [
                'name' => 'users.destroy',
                'description' => '禁用/启用用户',
                'group' => '用户列表',
                'menu' => '用户管理',
                'guard_name'=>'backend',
                'created_at' => $date,
                'updated_at' => $date
            ],
            [
                'name'=>'user-roles.index',
                'description'=>'用户角色列表',
                'group'=>'用户角色',
                'menu' => '用户管理',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'user-roles.store',
                'description'=>'新增用户角色',
                'group'=>'用户角色',
                'menu' => '用户管理',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'user-roles.update',
                'description'=>'编辑用户角色',
                'group'=>'用户角色',
                'menu' => '用户管理',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=>'admin-logs.index',
                'description' => '操作日志列表',
                'group'=>'操作日志',
                'menu' => '系统管理',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=> 'school-admin-logs.index',
                'description'=>'操作日志列表',
                'group'=>'操作日志',
                'menu' => '学校设置',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=> 'foods.index',
                'description'=>'食品列表',
                'group'=>'食品',
                'menu' => '食品管理',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=> 'food-types.index',
                'description'=>'食品种类列表',
                'group'=>'食品种类',
                'menu' => '食品管理',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=> 'book-rules.index',
                'description'=>'订餐规则列表',
                'group'=>'订单管理',
                'menu' => '订单管理',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
            [
                'name'=> 'book-orders.index',
                'description'=>'订单列表',
                'group'=>'订单管理',
                'menu' => '订单管理',
                'guard_name'=>'backend',
                'created_at'=>$date,
                'updated_at'=>$date
            ],
        ];
//        DB::table($tableNames['permissions'])->delete();
        foreach ($permissions as $value){
            if(!DB::table($tableNames['permissions'])->where([['name',$value['name']],['guard_name', "backend"]])->exists()){
                DB::table($tableNames['permissions'])->insert($value);
            }
        }
    }
}
